package cn.wp.ewallet.common.dao.impl;

import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.dao.PubItemDictDao;
import cn.wp.ewallet.common.model.entity.PubItemDictDo;
import org.springframework.stereotype.Repository;
import cn.wp.common.core.dao.JdbcSupportTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

/**
 * 数据字典项实体-数据访问层实现
 * Created by ganjie on 2020/01/09
 */
@Repository
public class PubItemDictDaoImpl implements PubItemDictDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public void updateTransfee(BigDecimal transFee) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("update pub_item_dict");
        sqlString.add("set ITEM_VALUE = ?");
        sqlString.add("where ITEM_CODE = 'trans_fee'");
        jdbcSupportTemplate.execute(sqlString.build(),new Object[]{transFee});

    }

    @Override
    public void updatementionFee(BigDecimal mentionFee) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("update pub_item_dict");
        sqlString.add("set ITEM_VALUE = ?");
        sqlString.add("where ITEM_CODE = 'mention_fee'");
        jdbcSupportTemplate.execute(sqlString.build(),new Object[]{mentionFee});

    }

    @Override
    public List<PubItemDictDo> selectPubItemDictByDicId(String dicId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select a.*");
        sqlString.add("from PUB_ITEM_DICT a");
        sqlString.add("where a.DIC_ID = ?");
        return jdbcSupportTemplate.selectList(sqlString.build(),new Object[]{dicId},PubItemDictDo.class);
    }

    @Override
    public PubItemDictDo selectPubItemDictByCode(String dicId, String code) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select a.*");
        sqlString.add("from PUB_ITEM_DICT a");
        sqlString.add("where a.DIC_ID = ? and a.item_code = ?");
        return jdbcSupportTemplate.selectObject(sqlString.build(),new Object[]{dicId, code},PubItemDictDo.class);
    }

    @Override
    public int updateItemValueByItemCode(PubItemDictDo pubItemDictDo) {
        String sql = "update pub_item_dict set item_value = ? where item_code = ?";
        return jdbcSupportTemplate.execute(sql,new Object[]{pubItemDictDo.getItemValue(),pubItemDictDo.getItemCode()});
    }
}

